package com.burgeon.backend.SHOP.service.Impl;

import com.burgeon.backend.SHOP.entity.Classify;
import com.burgeon.backend.SHOP.entity.ClassifyItem;
import com.burgeon.backend.SHOP.entity.Goods;
import com.burgeon.backend.SHOP.mappers.ClassifyItemMapper;
import com.burgeon.backend.SHOP.mappers.GoodsClassifyMapper;
import com.burgeon.backend.SHOP.service.ClassifyItemService;
import com.burgeon.backend.SHOP.service.util.MathUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class ClassifyItemServiceImpl implements ClassifyItemService {
    @Autowired
    private ClassifyItemMapper classifyItemMapper;
    @Autowired
    private GoodsClassifyMapper goodsClassifyMapper;

    @Override
    public List<Classify> showClassifyIstem(String account) {
        List<Classify> classifies= goodsClassifyMapper.getClassify(account);
        for (Classify classify:classifies) {
            List<ClassifyItem> classifyItem = classifyItemMapper.getClaItemByCid(classify.getId());
           classify.setClassifyItem(classifyItem);
        }
        return classifies;

    }

    /***
     * 根据小分类查询商品
     * @param classifyItemId
     * @param token
     * @return
     */
    @Override
    public List<Goods> getGoodsByClassifyItemId(Integer start,String classifyItemId,String discount, String token) {

        List<Goods> data = classifyItemMapper.getGoodsByClassifyItemId(start * 10, classifyItemId, token);
        for (Goods goods : data) {
            //计算会员价
            goods.setVipPrice(String.valueOf(MathUtil.multiply(new BigDecimal(goods.getOriginal()), new BigDecimal(discount), 0)));

        }
        return data;
    }


}
